<?php
// 定义变量并默认设置为空值
$nameErr = $pwdErr ="";
$name = $pwd = "";

if ($_SERVER["REQUEST_METHOD"] == "POST"){
    if (empty($_POST["name"])){
        $nameErr = "名字是必需的";
    }else{
        $name = validation_input ($_POST["name"]);
        // 检测名字是否只包含字母跟空格
        if (!preg_match("/^[a-zA-Z ]*$/",$name))
        {
            $nameErr = "只允许字母和空格"; 
        }
    }
    if (empty($_POST["pwd"])){
        $pwdErr = "密码是必需的";
    }else{
        $name = validation_input ($_POST["pwd"]);
        // 检测密码是否只包含字母跟空格
        if (!preg_match("/^[a-zA-Z ]*$/",$pwd)){
            $pwdErr = "只允许字母和空格"; 
        }
    }
    
}

function validation_input ($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}





?>